package service.impl;

import dao.VoteDao;
import dao.impl.VoteDaoImpl;
import entity.Vote;
import service.VoteService;
import utils.JDBCUtils;

import java.sql.Connection;
import java.util.List;

public class VoteServiceImpl implements VoteService {
    private VoteDao voteDao =new VoteDaoImpl();
    /**
     * 修改投票
     *
     * @return
     */
    @Override
    public boolean changeVote(String vName) {
        boolean boo =false;
        Connection conn =null;
        try{
            conn = JDBCUtils.startTransaction();
            Vote vote =new Vote(null,vName,null);
            int i = voteDao.updateVote(vote);
            if (i==1){
                boo=true;
            }else {
                throw new RuntimeException("投票失败!");
            }
            JDBCUtils.commit(conn);
        }catch (Exception e){
            JDBCUtils.rollback(conn);
            throw  new RuntimeException(e);
        }
        return boo;
    }

    /**
     * 根据vName查询投票
     *
     * @param vName
     * @return
     */
    @Override
    public List<Vote> queryVoteByvName(String vName) {
        return null;
    }
}
